package com.itzhoun.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itzhoun.entity.SysJobLog;
import com.itzhoun.service.JobLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author 周楠
 * @Date 2022/09/04/下午 1:01
 */
@Api("定时任务日志")
@RestController
@RequestMapping("/quartz/jobLog")
public class SysJobLogController {

    @Resource
    private JobLogService jobLogService;

    /**
     * 定时任务日志列表
     * @param sysJobLog
     * @return
     */
    @ApiOperation("定时任务日志")
    @GetMapping("/page")
    public IPage<SysJobLog> sysJobLogIPage(@RequestParam SysJobLog sysJobLog) {
        return jobLogService.page(new Page<>(1, 10), new QueryWrapper<SysJobLog>()
                .like(StringUtils.isNotBlank(sysJobLog.getJobName()), "job_name", sysJobLog.getJobName())
                .eq(StringUtils.isNotBlank(sysJobLog.getJobGroup()), "job_group", sysJobLog.getJobGroup()));
    }


    /**
     * 根据调度编号获取详细信息
     * @param jobLogId
     * @return
     */
    @ApiOperation("根据调度编号获取详细信息")
    @GetMapping("/{jobLogId}")
    public SysJobLog getSysJobLogDetail(@PathVariable Long jobLogId){
        return jobLogService.getById(jobLogId);
    }

    /**
     * 删除定时任务调度日志
     * @param jobLogIds
     */
    @ApiOperation("删除定时任务调度日志")
    @DeleteMapping("/{jobLogIds}")
    public void deleteJobLogIds(@PathVariable Long[] jobLogIds){
        jobLogService.removeByIds(Arrays.asList(jobLogIds));
    }

    /**
     * 清空日志
     */
    @ApiOperation("清空日志")
    @DeleteMapping("clean")
    public void cleanJobLog(){
        jobLogService.cleanJobLog();
    }



}
